  package org.flhy.step.idcard.id15to18;

  import org.pentaho.di.core.Const;
  import org.pentaho.di.core.exception.KettleException;
  import org.pentaho.di.core.row.RowDataUtil;
  import org.pentaho.di.trans.Trans;
  import org.pentaho.di.trans.TransMeta;
  import org.pentaho.di.trans.step.BaseStep;
  import org.pentaho.di.trans.step.StepDataInterface;
  import org.pentaho.di.trans.step.StepMeta;
  import org.pentaho.di.trans.step.StepMetaInterface;

  public class id15to18 extends BaseStep implements org.pentaho.di.trans.step.StepInterface
  {
    private id15to18Meta meta;
    private id15to18Data data;

    public id15to18(StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans)
    {
   super(stepMeta, stepDataInterface, copyNr, transMeta, trans);
    }

    public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
  this.meta = ((id15to18Meta)smi);
  this.data = ((id15to18Data)sdi);

    Object[] r = getRow();
    if (r == null)
      {
     setOutputDone();
      return false;
      }

    if (this.first) {
      this.data.previousMeta = getInputRowMeta().clone();
      this.data.outputMeta = this.data.previousMeta.clone();

      this.data.keynr = this.data.previousMeta.indexOfValue(this.meta.getFieldToUse());
      this.meta.getFields(this.data.outputMeta, getStepname(), null, null, this, this.repository, this.metaStore);

      this.data.sourceValueMeta = getInputRowMeta().getValueMeta(this.data.keynr);
      }

    Object sourceData = r[this.data.keynr];
     String source = this.data.sourceValueMeta.getCompatibleString(sourceData);
    IdentificationCodeUtil.Verify(source);
    String target = IdentificationCodeUtil.uptoeighteen(source);


    if (!Const.isEmpty(this.meta.getResultField())) {
       r = RowDataUtil.resizeArray(r, this.data.outputMeta.size());
      r[(this.data.outputMeta.size() - 1)] = target;
      }
      else {
       r[this.data.keynr] = target;
      }

    putRow(this.data.outputMeta, r);

     return true;
    }
  }
